Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure Renovate to suggest AGP version bumps #1742

Merged
merged 11 commits into from
Jan 8, 2025

Conversation

gabrielfeo
Copy link
Member

@gabrielfeo gabrielfeo commented Jan 3, 2025

Fully automate the bumping of AGP versions to the latest patch. While there's an existing workflow for bumping the AGP versions in this project, it must be manually triggered specifying the new version. Renovate can fill this gap by suggesting updates whenever new versions come out. Other kinds of bumps are still handled by Dependabot.

Renovate

Renovate is a tool like Dependabot but much more flexible. It has built-in "managers" such as maven, gradle, and pip_requirements that look for certain patterns in certain files, then query "datasources" for newer versions. No built-in manager supports the custom versions.json file, but Renovate allows for creating a custom regex-based manager.

Renovate custom manager

A Renovate config file is added with a custom "regex" manager. This can instruct Renovate to parse any version on any file. The goal is to detect and update AGP versions annotated with a comment:

# renovate: AGP version
8.6.0

The "manager" config declares

  • what files it should process
  • what it should consider a version definition within those files
  • what "datasource" it should query for newer versions
  • what "versioning" (scheme) the versions adhere to
  • the dependency name
  • the Maven registry URL the dependency comes from
{
  // Matches AGP versions annotated with a "renovate: AGP version" comment
  customType: "regex",
  fileMatch: [
    "src/main/resources/versions\\.json5",
    "gradle\\.properties",
  ],
  matchStrings: [
    // For JSON: the first double-quoted string below the comment line, e.g. "1.0.0"
    "\/\/ renovate: AGP version\\s+?\"(?<currentValue>\\S+?)\"",
    // For properties: the value of the first property below the comment line, e.g. anyProperty=1.0.0
    "# renovate: AGP version\\s+?\\S+?=(?<currentValue>\\S+?)(?:\\s|$)",
  ],
  "datasourceTemplate": "maven",
  "versioningTemplate": "maven",
  "depNameTemplate": "com.android.tools.build:gradle",
  "registryUrlTemplate": "https://dl.google.com/dl/android/maven2/",
},

An example PR is available in a fork: gabrielfeo#10.

image

The last four elements are commonly set on each comment and captured with regex (example), but I opted to centralize them in the Renovate config to minimize duplication, simplify the comments and the regex that parses them.

Changes

  • Annotate AGP versions in versions.json with a "renovate: AGP version" comment
    • Rename the file to versions.json5 to keep syntax highlighting support when adding comments
    • Change all JsonSlurpers to LAX mode, which is lenient about comments (Groovy has no support for JSON5)
  • Add a Renovate config to bump versions in versions.json5 and gradle.properties too (for the build-time check described below)
  • Change plugin tests to no longer require changes on every patch bump PR. "expectedOutcomes" JSON files are now minor-specific and WorkaroundTest no longer specifies patch numbers. The existing workflow updated the tests automatically, but it can't be as easily done with Renovate. Thanks to @erichaagdev for this suggestion.
  • Declare the latest AGP version in gradle.properties and fail the build if it's missing from versions.json5. The goal is to have Renovate create a "nudge" PR if a new major or minor comes out (versions.json5 has major/minor bumps disabled in order to keep older minor versions in the list of "supportedVersions"). The property isn't used for anything else. Thanks to @erichaagdev for this suggestion.

These changes were tested running the Renovate GitHub App against a fork. After adding the dv.json5 preset to the config, which is located in a private Gradle repository, they were tested with dry-runs of our self-hosted Renovate runner, which has access to that repository.

(cherry picked from commit 86474cd14f8ea7a4eef7d7705bc8b15f0cb9dd2d)
(cherry picked from commit 994168bcd78831577933c111b9cc1c1dee5cba3b)
@gabrielfeo gabrielfeo force-pushed the gf/agp-pre-release-bump-prs branch 2 times, most recently from e7a9b26 to 2e4ec1c Compare January 6, 2025 12:39
(cherry picked from commit d82c4d7103211d524d4cb4ff8dbb6311ee354ab1)
@gabrielfeo gabrielfeo force-pushed the gf/agp-pre-release-bump-prs branch from 22061a8 to c2cef72 Compare January 6, 2025 14:15
Allow unlimited PRs

Group changes to versions.json5

Improve renovate.json5 comments
@gabrielfeo gabrielfeo force-pushed the gf/agp-pre-release-bump-prs branch from c2cef72 to 36964bf Compare January 6, 2025 14:37
@gabrielfeo gabrielfeo marked this pull request as ready for review January 7, 2025 12:51
@gabrielfeo gabrielfeo requested a review from a team January 7, 2025 12:52
Copy link
Member

@cdsap cdsap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome work @gabrielfeo

@gabrielfeo gabrielfeo merged commit fc46588 into gradle:main Jan 8, 2025
4 checks passed
@gabrielfeo gabrielfeo deleted the gf/agp-pre-release-bump-prs branch January 8, 2025 17:57
gabrielfeo added a commit that referenced this pull request Jan 13, 2025
Since #1742, the `generate_versions` CI job [succeeds even though it
can't parse the JSON file][1]. Parsing fails because `jq` [doesn't
support JSON5][2]. The job succeeds silently despite this failure
because it's ran inside [command substitution][3]. This currently
results in #1751 not running proper tests.

Fix the `generate_versions` CI job to correctly parse the JSON5 file by
stripping comment lines before passing its content to `jq`. Also ensure
the job will fail if the step fails by running it once outside command
substitution and ensuring `pipefail` is on. This replaces the "debug"
step.

[1]:
https://github.com/gradle/android-cache-fix-gradle-plugin/actions/runs/12717112831
[2]: jqlang/jq#1571
[3]:
https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html
gabrielfeo added a commit that referenced this pull request Jan 15, 2025
In #1742, Renovate was set up with a more usual standard `regex` matcher
configuration, which is to search for versions in lines annotated with a
comment `// renovate: ...`. However, the `versions.json` file is parsed
by several tools which don't support JSON5 or any form of comments,
namely Groovy's `json` package and `jq`. Groovy `json` required using a
lenient mode (#1742), which may suppress useful validations, while `jq`
required stripping the comments beforehand (#1752). Moving away from
JSON5 would be a simpler solution.

Revert the `versions.json` back from JSON5 to plain JSON and change the
Renovate config to match the version properties based on the fact that
their values are lists, e.g. `"8.8.0": [`. Matching the version in
`gradle.properties` is also simplified to no longer require a comment.

Tested with a [dry-run of gradle/renovate-agent][2] against this repo
and the Renovate GitHub app against a fork, which created an [example
PR][1].

[1]:
gabrielfeo#14 (comment)
[2]:
https://github.com/gradle/renovate-agent/actions/runs/12771500371/job/35598810573
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants